package com.erp.erp_ui.Cost.Service;

import com.erp.erp_entitys.Cost.req.QueryCostDetailWarehouseReq;
import com.erp.erp_entitys.Cost.vo.QueryCostDetailWarehouseVO;
import com.erp.erp_entitys.Cost.vo.QueryPlanInStoreProductInfoVo;
import com.erp.erp_servers.Cost.CostApportionmentService;
import com.erp.erp_servers.Cost.CostDetailService;
import com.erp.utils.DateUtils;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

/**
 * @author zjk
 * @version 1.0
 * @description
 * @date 2021-06-14 20:57
 */
@Service
public class CostDetailAllService {

    private final CostDetailService costDetailService;

    private final CostApportionmentService costApportionmentService;

    public CostDetailAllService(CostDetailService costDetailService, CostApportionmentService costApportionmentService) {
        this.costDetailService = costDetailService;
        this.costApportionmentService = costApportionmentService;
    }


    /**
     * 整合根据出运编码获取备货入库信息
     * @param req
     * @return
     */
    public List<QueryCostDetailWarehouseVO>  getCostDetailWarehouseList(QueryCostDetailWarehouseReq req){
        List<QueryCostDetailWarehouseVO> list=costDetailService.getUnShareCostDetails(req);
        for (QueryCostDetailWarehouseVO p:list) {
            List<QueryPlanInStoreProductInfoVo> productInfoVos=costDetailService.getPlanInStoreInfo(p.getInvoiceCode());
            for (QueryPlanInStoreProductInfoVo g:productInfoVos) {
                g.setTimeStr(DateUtils.format(g.getTime(),DateUtils.DATE_PATTERN));
                g.setFeeCode(p.getFeeCode());
            }
            p.setProductInfoVoList(productInfoVos);
        }
        Iterator iterator=list.iterator();
        while (iterator.hasNext()){
            QueryCostDetailWarehouseVO p= (QueryCostDetailWarehouseVO)iterator.next();
            //如果备货表里没有对应得信息，则去掉该集合
            if (p.getProductInfoVoList().size()==0){
                iterator.remove();
            }
        }

        return list;
    }
}
